package lab03.test03;

import java.io.*;

public class Test03 {
    public static void main(String[] args) {

        String path = "D:\\java实验\\lab03test03.txt";

        FileOutputStream fileOutputStream = null;
        FileInputStream fileInputStream = null;
        FileWriter fileWriter = null;

        try {

            //通过字节输出流写入beijing欢迎你！
            fileInputStream = new FileInputStream(path);
            fileOutputStream = new FileOutputStream(path);

            String line = "Beijing欢迎你！";
            byte[] bytes = line.getBytes();
            fileOutputStream.write(bytes);

            //通过字节输入流读出文件中的内容并显
            int data = 0;
            while ((data = fileInputStream.read(bytes)) != -1) {
                String string = new String(bytes);
                System.out.println(string);
            }

            //在已有文件中再追加“我的学号是：你自己的学号”
            fileWriter = new FileWriter("D:\\java实验\\test.txt");
            fileWriter.write("我是学号是：你自己的学号");

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
